﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

namespace HZ.Supervise.Web.Secondphase.ReportHospital
{
    public partial class ResionRemark :BasePage
    {
        HZ.Supervise.IBLL.IBLL_Prescription iPrescription = HZ.Supervise.BLLFactory.IBl_Prescription();
        public  IList<HZ.Supervise.Model.Subsidy> Subsidyls=new List<HZ.Supervise.Model.Subsidy>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["SubsidyID"].ToString() == "1")
                {
                    Label1.Text = "撤销原因";
                    Label2.Text = "撤销原因";
                    btnFinish.Visible = true;
                    btnFinish1.Visible = false;
                }
                else 
                {
                    Label1.Text = "审核未通过";
                    Label2.Text = "审核未通过";
                    btnFinish.Visible = false;
                    btnFinish1.Visible = true;
                }
                bind();

            }
        }
       public void bind() 
        {
            int i;
            HZ.Data.QueryModel qm = new HZ.Data.QueryModel();
            qm["SubsidyID"] = Request.QueryString["SubsidyID"].ToString();
            qm["SortFields"] = " SubsidyID asc";
            Subsidyls = iPrescription.GetSubsidyTable(qm, 0, 1, out i);
            txtProName.Text = Subsidyls[0].SubsidyName;
            txtHosPSubsidiesAmount.Text = Subsidyls[0].Amount.ToString();
            txtHosPSbsidyAmount.Text = Subsidyls[0].SubsidyAmount.ToString();
        }
        /// <summary>
        /// 撤销原因
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnFinish_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtBZ.Text.Trim()))
            {
                HZ.Web.WebUtil.Alert("请填写撤销原因！");
            }
            else
            {
                int i;
                HZ.Data.QueryModel qm = new HZ.Data.QueryModel();
                qm["SubsidyID"] = Request.QueryString["SubsidyID"].ToString();
                qm["SortFields"] = " SubsidyID asc";
                Subsidyls = iPrescription.GetSubsidyTable(qm, 0, 1, out i);
                if (Subsidyls.Count > 0)
                {
                    Subsidyls[0].Remark += CurrentAccount.GetUser().UserName+"在"+DateTime.Now+"撤销结算单，撤销原因如下："+txtBZ.Text.Trim();
                    Subsidyls[0].State = 1;
                    if (iPrescription.UpdateSubsidyStateBacth(Subsidyls) == 1)
                    {
                        HZ.Web.WebUtil.Alert("撤销成功！");
                    }
                    else
                    {
                        HZ.Web.WebUtil.Alert("撤销失败！");
                    }
                }
            }
        }

        protected void btnFinish1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtBZ.Text.Trim()))
            {
                HZ.Web.WebUtil.Alert("请填写未通过原因！");
            }
            else
            {
                int i;
                HZ.Data.QueryModel qm = new HZ.Data.QueryModel();
                qm["SubsidyID"] = Request.QueryString["SubsidyID"].ToString();
                qm["SortFields"] = " SubsidyID asc";
                Subsidyls = iPrescription.GetSubsidyTable(qm, 0, 1, out i);
                if (Subsidyls.Count > 0)
                {
                    Subsidyls[0].Remark += CurrentAccount.GetUser().UserName + "在" + DateTime.Now + "审核结算单，未通过原因如下：" + txtBZ.Text.Trim();
                    Subsidyls[0].State = 0;
                    if (iPrescription.UpdateSubsidyStateBacth(Subsidyls) == 1)
                    {
                        HZ.Web.WebUtil.Alert("提交成功！");
                        Page.RegisterStartupScript("aa", "<script>addAreaInfo()</script>");
                    }
                    else
                    {
                        HZ.Web.WebUtil.Alert("提交失败！");
                    }
                }
            }
        }
    }
}
